<template>
  <div>
    <div class="account-pages"></div>
    <div class="clearfix"></div>
    <div class="wrapper-page">
      <div class="text-center">
        <a href="/" class="logo">
          <span>
            Tao
            <span>Yun</span>
          </span>
        </a>
      </div>
      <div class="m-t-40 card-box">
        <div class="text-center">
          <h4 class="text-uppercase font-bold m-b-0">登 录</h4>
        </div>
        <div class="panel-body">
          <div  class="form-horizontal m-t-20">
            <div class="form-group">
              <div class="col-xs-12">
              账号(工号)：
                <input
                  class="form-control"
                  v-model="user_number"
                  type="text"
                  required
                  placeholder="user_number"
                >
              </div>
            </div>

            <div class="form-group">
              <div class="col-xs-12">
              密码：
                <input
                  class="form-control"
                  v-model="password"
                  type="password"
                  required
                  placeholder="password"
                >
              </div>
            </div>

            <div class="form-group text-center m-t-30">
              <div class="col-xs-12">
                <button
                  class="btn btn-custom btn-bordred btn-block waves-effect waves-light"
                  @click="signin(user_number,password)"
                >Log In</button>
              </div>
            </div>
          </div>
          <div class="col-sm-12">
            <a href="/forget" class="text-muted">
              <i class="fa fa-lock m-r-5"></i> 忘记密码？
            </a>
          </div>
        </div>
      </div>
      <!-- end card-box-->
    </div>
    <!-- end wrapper page -->
  </div>
</template>

<script>
// import axios from "axios";
export default {
  data() {
    return {
      user_number: "",
      password: "",
      err_msg:"",
      
    };
  },
  methods: {
    open_error(mes) {
        this.$notify.error({
            title: "错误",
            message: mes,
            position: "bottom-right"
        });
    },

    // 登录   未实现记住我功能
    signin(userNumber,password) {
        var formData=new FormData();
        formData.append('userNumber',userNumber);
        formData.append('password',password);
        
        this.$axios.post('/api/taoyun/v1/login',formData)
        .then((res) => {
            if(res.data.code=="200"){
                window.localStorage.setItem("tokenLogin", res.data.data);  // 存储token到缓存中
                this.$router.push({path:"/"});
            }
            else if(res.data.code=="500"){
                this.open_error(res.data.msg);
            }
        })
        .catch((err) => {
           console.log(err);
        });

    }
  }
};
</script>